﻿using System.Configuration;
// ReSharper disable InconsistentNaming

namespace Globsite.Globalization.Mvc
{
    public class GlobsiteConfigSection : ConfigurationSection
    {
        #region Keys

        public const string SectionName = "globsite";
        
        public const string DbResourcesKey = "dbResources";

        #endregion

        private static GlobsiteConfigSection instance;

        public static GlobsiteConfigSection Instance
        {
            get { return instance ?? (instance = (GlobsiteConfigSection)ConfigurationManager.GetSection(SectionName)); }
        }

        [ConfigurationProperty(DbResourcesKey)]
        public DbResourcesConfigElement DbResources
        {
            get { return (DbResourcesConfigElement)this[DbResourcesKey]; }
            set { this[DbResourcesKey] = value; }
        }
    }

    public class DbResourcesConfigElement : ConfigurationElement
    {
        #region Keys

        // Library
        public const string ConnectionStringNameKey = "connectionStringName";
        public const string ResourceTableNameKey = "resourceTableName";
        public const string IgnoreCaseKey = "ignoreCase";
        public const string CreateResourceIfNotExistsKey = "createResourceIfNotExists";
        public const string MissingResourceValueKey = "missingResourceValue";

        // T4 Template
        public const string T4_CreateResourceTableIfNotExistsKey = "T4_createResourceTableIfNotExists";
        public const string T4_ResourceClassNameKey = "T4_resourceClassName";
        public const string T4_NamespacePrefixKey = "T4_namespacePrefix";

        #endregion

        [ConfigurationProperty(ConnectionStringNameKey, IsRequired = true)]
        public string ConnectionStringName
        {
            get { return (string)this[ConnectionStringNameKey]; }
            set { this[ConnectionStringNameKey] = value; }
        }

        [ConfigurationProperty(ResourceTableNameKey, DefaultValue = "Resources", IsRequired = false)]
        public string ResourceTableName
        {
            get { return (string)this[ResourceTableNameKey]; }
            set { this[ResourceTableNameKey] = value; }
        }

        [ConfigurationProperty(IgnoreCaseKey, DefaultValue = "false", IsRequired = false)]
        public bool IgnoreCase
        {
            get { return (bool)this[IgnoreCaseKey]; }
            set { this[IgnoreCaseKey] = value; }
        }

        [ConfigurationProperty(CreateResourceIfNotExistsKey, DefaultValue = "true", IsRequired = false)]
        public bool CreateResourceIfNotExists
        {
            get { return (bool)this[CreateResourceIfNotExistsKey]; }
            set { this[CreateResourceIfNotExistsKey] = value; }
        }

        [ConfigurationProperty(MissingResourceValueKey, DefaultValue = "${StringEmpty}", IsRequired = false)]
        public string MissingResourceValue
        {
            get { return (string)this[MissingResourceValueKey]; }
            set { this[MissingResourceValueKey] = value; }
        }

        [ConfigurationProperty(T4_CreateResourceTableIfNotExistsKey, DefaultValue = "true", IsRequired = false)]
        public bool T4_CreateResourceTableIfNotExists
        {
            get { return (bool)this[T4_CreateResourceTableIfNotExistsKey]; }
            set { this[T4_CreateResourceTableIfNotExistsKey] = value; }
        }

        [ConfigurationProperty(T4_ResourceClassNameKey, DefaultValue = "Resources", IsRequired = false)]
        public string T4_ResourceClassName
        {
            get { return (string)this[T4_ResourceClassNameKey]; }
            set { this[T4_ResourceClassNameKey] = value; }
        }

        [ConfigurationProperty(T4_NamespacePrefixKey, IsRequired = false)]
        public string T4_NamespacePrefix
        {
            get { return (string)this[T4_NamespacePrefixKey]; }
            set { this[T4_NamespacePrefixKey] = value; }
        }
    }
}
